#!/usr/bin/perl

use utf8;
use strict;
use warnings;
use FindBin qw( $RealBin );
use lib $RealBin .'/../lib';
use Test::More;
use Module::CoreList;

# module-to-verion mapping
# 0 means we dont care
my %requirements = (
    'Readonly'              => 0,
    'Test::MockModule'      => 0,
    'DBIx::Class'           => 0,
    'DBIx::Class::Schema'   => 0,
    'Net::NBName'           => 0,
    'Hash::AsObject'        => 0,
    'Class::Base'           => 0,
    'Exporter::Lite'        => 0,
    'lib::abs'              => 0,
    'ToolSet'               => 0,
    'DateTime'              => 0,
    'Test::Compile'         => 0,
    'File::Find::Rule'      => 0,
    'parent'                => 0,
    'Class::Accessor::Fast' => 0,
    'DBI'                   => 0,
    'Test::NoTabs'          => 1.0,
);

if ( %requirements ) {
    plan( tests => ( scalar keys %requirements ) * 2 );

    for my $each_module ( sort keys %requirements ) {
        my $wanted = $requirements{ $each_module };

        if ( use_ok $each_module ) {
            if ( $wanted ) {
                my $actual = $each_module->VERSION;

                cmp_ok( $actual, '>=', $wanted, $each_module );
            }
            else {
                pass $each_module .' loaded';

                diag $each_module .' in CoreList'
                    if defined Module::CoreList->first_release( $each_module );
            }
        }
        else {
            fail 'cannot load '. $each_module;
        }
    }
}
else {
    plan( skip_all => 'without requirements' );
}
